package com.zuxia.impservices;

import java.util.Date;
import java.util.List;

import org.hibernate.Query;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.zuxia.iDao.InfocenterinfoDAOI;
import com.zuxia.iDao.InfotypeinfoDAOI;
import com.zuxia.iservices.InformationServicesI;
import com.zuxia.po.Infocenterinfo;
import com.zuxia.po.Infotypeinfo;
import com.zuxia.po.Staffindo;
import com.zuxia.util.PageModel;

public class InformationServices implements InformationServicesI {
//私有化Dao
	private InfotypeinfoDAOI infotypeinfoDAO;
	private InfocenterinfoDAOI infocenterinfoDAO ;
	
	public InfotypeinfoDAOI getInfotypeinfoDAO() {
		return infotypeinfoDAO;
	}

	public void setInfotypeinfoDAO(InfotypeinfoDAOI infotypeinfoDAO) {
		this.infotypeinfoDAO = infotypeinfoDAO;
	}

	public InfocenterinfoDAOI getInfocenterinfoDAO() {
		return infocenterinfoDAO;
	}

	public void setInfocenterinfoDAO(InfocenterinfoDAOI infocenterinfoDAO) {
		this.infocenterinfoDAO = infocenterinfoDAO;
	}

	public Boolean addType(String Type) {
		
	return  infotypeinfoDAO.addTyep(Type);
	}

	public List selectType() {
		
		return infotypeinfoDAO.findAll();
	}

	public Boolean addCenter(String centerName, int centerType,Date centerTime, String centerText) {
		
		return infotypeinfoDAO.addCenter(centerName, centerType, centerTime, centerText) ;
		
		
	}
	//分页查询所有新闻
	public String queryall(int pageNumber, int limit, String icititle) {
		System.out.println("ss1213131");
		//得到所有新闻数量
		int total =infocenterinfoDAO.showInfocenterinfo(icititle).size();
		System.out.println("-----------------dasdasdda");
		//得到新闻信息
		List<Infocenterinfo> list =infocenterinfoDAO.showPageModelList(pageNumber, limit, icititle);
		//将分页参数存入分页工具类中		
		PageModel<Infocenterinfo> pModel = new PageModel<Infocenterinfo>(total, pageNumber, limit);
		pModel.setList(list);
		//第二个参数禁用FastJson的“循环引用检测”特性。（防止前台的json出现$ref引用）
		String json = JSONArray.toJSONString(pModel, SerializerFeature.DisableCircularReferenceDetect);
		return json;
	}

	public Boolean xzCut(int cid) {
	//根據id查到對象再調用刪除的方法
		Boolean s=infocenterinfoDAO.xzCut(cid);
		return s;	
	}
	// 根据id查询的方法
	public Infocenterinfo show_Center(int cid) {
		Infocenterinfo info=infocenterinfoDAO.findById(cid);
		return info;
		
	}
	//根据id修改新闻数据
		public Boolean updateCenter(int cid, String centerName, int centerType, Date centerTime, String centerText) {
			Infocenterinfo i=infocenterinfoDAO.idShowInfocenterinfo(cid);
			Infotypeinfo it=infotypeinfoDAO.idShowInfotypeinfo(centerType);
			//换个类
			i.getInfotypeinfo().getInfocenterinfos().remove(i);
			i.setIcititle(centerName);
			i.setIcitime(centerTime);
			i.setInfotypeinfo(it);
			i.setIcicontext(centerText);
			Boolean c=infocenterinfoDAO.updateCenter(i);
			return c;
		}

		public String showAll(int itiid ,int pageNumber,int limit) {
			//得到相应新闻数量
			int total =infocenterinfoDAO.showAll(itiid).size();
			System.out.println("-----------------aaaaaa");
			//得到新闻信息
			List<Infocenterinfo> list =infocenterinfoDAO.idshowPageModelList(itiid,pageNumber, limit);
			//将分页参数存入分页工具类中		
			PageModel<Infocenterinfo> pModel = new PageModel<Infocenterinfo>(total, pageNumber, limit);
			pModel.setList(list);
			//第二个参数禁用FastJson的“循环引用检测”特性。（防止前台的json出现$ref引用）
			String json = JSONArray.toJSONString(pModel, SerializerFeature.DisableCircularReferenceDetect);
			return json;
		}

}
